package dbUnit;

import java.sql.*;

public class databaseAccess{
	public static void main(String[] args) {
		System.out.println("MySQL Connect Example.");
		Connection conn = null;
		//Database config
		String url = "jdbc:mysql://localhost/";
		String dbName = "chalmersbot";
		String driver = "com.mysql.jdbc.Driver";
		String userName = "webapp"; 
		String password = "webapp";

		try {
			Class.forName(driver).newInstance();
			conn = DriverManager.getConnection(url+dbName,userName,password);
			System.out.println("Connected to the database");	

			try{
				Statement st = conn.createStatement();
				ResultSet res = st.executeQuery("SELECT code FROM Course");
				while (res.next()){
					System.out.println(res.getString(1));
				}
			} catch (SQLException s) {
				System.out.println("SQL statement is not executed!");
			}
			conn.close();
			System.out.println("Disconnected from database");
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}